#include "support_common.h" /* include peripheral declarations and more */
#include <stdio.h>
#include "dtim.h"

void dtim0_delay(int p_usecs)
{
	MCF_DTIM_DTCN(0) = 0x00000000;
	if (p_usecs-1 == 249999)
		MCF_DTIM_DTRR(0) = 0x3D08F;
		//MCF_DTIM_DTRR(0) = 0x0222222;
	else if (p_usecs-1 == 349999)
			MCF_DTIM_DTRR(0) = 0x5572F;
	else if (p_usecs-1 == 449999)
			MCF_DTIM_DTRR(0) = 0x6DDCF;
	else if (p_usecs-1 == 549999)
			MCF_DTIM_DTRR(0) = 0x8646F;
	MCF_DTIM_DTER(0) |= 0x02;
	MCF_DTIM_DTMR(0) |= 0x0001;
	while (~MCF_DTIM_DTER(0) & 0x02) 
	{
		
	}
}
void dtim0_init()
{
	MCF_DTIM_DTMR(0) &= 0xFFFE;
	MCF_DTIM_DTMR(0) |= 0x4F0A;
	MCF_DTIM_DTXMR(0) = 0x40;
}

